import java.util.*;

class Person{
    private int age;
    private String sex;
    public static String country="中国";//用static修饰成员变量，让它存储在方法区里




    public Person(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
        System.out.println("带3个参数的构造方法");
    }

    public void sleep(){
        System.out.println(this.name+"在睡觉！");
    }
    public void show (){
        System.out.println("姓名:"+this.name+" 年龄:"+this.age+" 性别:"+this.sex);
    }


    private String name;
    public String getName() {
        return name;
    }
    public Person(){
        System.out.println("不带参数的构造方法");
    }
    {
        System.out.println("构造块/实例代码块/非静态代码块");
        this.name="zhangsan";
    }
    static{
        System.out.println("静态代码块");
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
    public void eat(){
        getCountry();//1
        System.out.println(this.name+"在干饭!");
    }

    public static String getCountry() {
        Person person6=new Person();
        person6.eat();
        return country;
    }
    /*
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return this.name;
    }
*/


}
public class Test {
    public static void main(String[] args) {
        Person person7=new Person();
        System.out.println(person7.getName());

        System.out.println("**********");
        Person person8=new Person();
        System.out.println(person8.getName());
    }
    public static void main1(String[] args) {
/*
        Person person1=new Person();
        person1.setName("zhangsan");//虽然封装了，但是此时name的值已经被公开的方法 修改成zhangsan了
        System.out.println(person1.getName());
        person1.eat();
        System.out.println(person1.country);//利用 对象. 的方式访问静态变量country
        System.out.println(Person.country);//利用 类名. 访问静态变量country
*/

        Person person3=null;
        System.out.println(person3.country);
//        person1.show();


        //类的实例化
        //通过.访问成员变量，并且赋值
        //person1.name="zhangsan";

/*
        person1.age=19;
        person1.sex="男";
        person1.show();
        Person person2=new Person();*/
        //        Person person1 = new Person();
//        person1.show();
//        System.out.println("*****");
//        Person person2 = new Person("lisi", 20, "女");
//        person2.show();

    }
}
